//用类实现一个 显示电子时钟的程序
//(1)time头文件 调用本地时间
//(2)class实现封装


#include <iostream>
#include <time.h>
#include <unistd.h>
using namespace std;
class Clock
{
public:
    Clock()
    {
        time_t t = time(NULL);
        tm local = *localtime(&t);
        _hour = local.tm_hour;
        _minute = local.tm_min;
        _second = local.tm_sec;
    }
    void run()
    {
        for (;;)
        {
            tick();
            show();
        }
    }

private:
    void tick()
    {
        sleep(1);
        if (++_second == 60)
        {
            _second = 0;
            if (++_minute == 60)
            {
                _minute = 0;
                if (++_hour == 24)
                {
                    _hour = 0;
                }
            }
        }
    }
    void show()
    {
        system("cls");
        cout << _hour << ":" << _minute << ":" << _second << endl;
    }
    int _hour;
    int _minute;
    int _second;
};
int main()
{
    Clock c;
    c.run();
    return 0;
}